import copy
import datetime
import json
import logging
import time

import moment
import requests
import urllib3
from pyquery import PyQuery as jq
from retry import retry
from termcolor import colored
import moment
import pandas as pd
def timeSections(starttimes, endtimes, sectiondays=30, sectionshours=1, formats=None):
        if not starttimes:
            starttimes = moment.now().replace(minutes=0, seconds=0).add(days=-sectiondays)
        else:
            starttimes = moment.date(starttimes)
        if not endtimes:
            endtimes = moment.now().replace(minutes=0, seconds=0)
        else:
            endtimes = moment.date(endtimes)

        while starttimes < endtimes:
            nexttimes = copy.deepcopy(starttimes).add(hours=sectionshours)
            if formats:
                yield starttimes.format(formats), nexttimes.format(formats)
            else:
                yield starttimes, nexttimes
            starttimes = copy.deepcopy(nexttimes).add(hours=24)

timelist = list(timeSections('2016-01-01', '2018-12-31', None, 24 * 14, 'YYYY-MM-DD'))
print(len(timelist))